package com.henghai.zhenxuan.domain.request;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

import com.henghai.zhenxuan.data.api.RaiseFeedCheckApi;
import com.henghai.zhenxuan.data.api.RaiseGetFeedApi;
import com.henghai.zhenxuan.data.api.RaiseListApi;
import com.henghai.zhenxuan.data.api.RaiseSetFeedApi;
import com.henghai.zhenxuan.data.bean.CheckFeedNumBean;
import com.henghai.zhenxuan.data.bean.HttpBean;
import com.henghai.zhenxuan.data.bean.RaiseBean;
import com.henghai.zhenxuan.data.repository.DataRepository;
import com.kunminx.architecture.data.response.DataResult;
import com.kunminx.architecture.domain.message.MutableResult;
import com.kunminx.architecture.domain.message.Result;
import com.kunminx.architecture.domain.request.Requester;

import org.jetbrains.annotations.NotNull;

public class RaiseListRequester extends Requester implements DefaultLifecycleObserver {
    private final MutableResult<DataResult<HttpBean<RaiseBean>>> noticeResult = new MutableResult<>();
    private final MutableResult<DataResult<HttpBean<CheckFeedNumBean>>> receiveTaskResult = new MutableResult<>();
    private final MutableResult<DataResult<HttpBean>> receiveGetFeedResult = new MutableResult<>();
    private final MutableResult<DataResult<HttpBean>> receiveSetFeedResult = new MutableResult<>();
    private final MutableResult<DataResult<HttpBean>> receiveFeedCountResult = new MutableResult<>();

    public Result<DataResult<HttpBean<RaiseBean>>> getRaiseListTaskResult() {
        return noticeResult;
    }

    public MutableResult<DataResult<HttpBean<CheckFeedNumBean>>> getReceiveTaskResult() {
        return receiveTaskResult;
    }
    public MutableResult<DataResult<HttpBean>> getReceiveGetFeedResult() {
        return receiveGetFeedResult;
    }
    public MutableResult<DataResult<HttpBean>> getReceiveSetFeedResult() {
        return receiveSetFeedResult;
    }

    public MutableResult<DataResult<HttpBean>> getReceivegetFeedCountResult() {
        return receiveFeedCountResult;
    }

    public void requestRaiseList(LifecycleOwner lifecycleOwner, String pageNum, String pageSize) {
        DataRepository.getInstance().raisrList(lifecycleOwner, new RaiseListApi(), noticeResult::postValue);
    }

    public void cancelLogin() {

    }
    /**
     * +
     * 检查是否可以获取饲料
     */
    public void checkAcquire(LifecycleOwner lifecycleOwner) {
        DataRepository.getInstance().canAcquire(lifecycleOwner, new RaiseFeedCheckApi(), receiveTaskResult::postValue);
    }
    /**
     * 获取饲料
     * @param owner
     */
    public void getFeed(LifecycleOwner owner, String userId){
        DataRepository.getInstance().getFeed(owner, new RaiseGetFeedApi(userId,"1"), receiveGetFeedResult::postValue);
    }
    /**
     * 查询饲料饲料
     * @param owner
     */
    public void getFeedCount(LifecycleOwner owner){
        DataRepository.getInstance().getFeedConut(owner, new RaiseFeedCheckApi(), receiveFeedCountResult::postValue);
    }

    /**
     * 投喂饲料
     * @param owner
     */
    public void setFeed(LifecycleOwner owner, String userId,String petId){
        DataRepository.getInstance().setFeed(owner, new RaiseSetFeedApi(userId,petId,"1"), receiveSetFeedResult::postValue);
    }

    @Override
    public void onStop(@NonNull @NotNull LifecycleOwner owner) {
        cancelLogin();
    }
}
